import { find, instantiate, Node, Prefab, sp } from "cc";
import { AssetLoader } from "../scripts/framework/loader/AssetLoader";
import { loaderMgr, LoaderMgr } from "../scripts/framework/loader/LoaderMgr";
import { resourcesMgr } from "../scripts/framework/loader/ResourcesMgr";

export class WindowNode {

    public node: Node;

    public loader: AssetLoader;

    public name: string;

    constructor(name: string) {
        this.name = name;
        this.loader = LoaderMgr.getInstance().get(this);
        this.onCtor();
    }

    onCtor(): void {
        this.loader.load(this.name, Prefab, (err: Error, prefab: Prefab) => {
            this.node = instantiate(prefab);
            this.node.setParent(window.windowParentNode);
            let btn = find('Button', this.node)
            btn.on('click', () => {
                this.close();
            }, this);

        }, 'test1')

    }

    close(): void {
        LoaderMgr.getInstance().releaseLoader(this);
        this.node.destroy();
    }

}
